#include <string.h>
#include <stdlib.h>

#include "global.h"
#include "logger.h"

static log4c_category_t* s_pCategory;

int InitLogger()
{
    setenv("LOG4C_RCPATH", g_szConfPath, 1);

    if(0 != log4c_init())
    {
        printf("loading '%s/log4crc' error!\n", g_szConfPath);
        return -1;
    }

    s_pCategory = log4c_category_get(g_szInstName);
    if(!s_pCategory)
        return -2;

    return 0;
}

__attribute__((format(printf, 2, 3)))
void WriteLog(int nPriority, const char* pszFormat, ...)
{
    if(!log4c_category_is_priority_enabled(s_pCategory,nPriority))
        return;

    va_list ap;

    va_start(ap, pszFormat);
    log4c_category_vlog(s_pCategory, nPriority, pszFormat, ap);
    va_end(ap);
}


void DeinitLogger()
{
/*
    if(s_pCategory)
        log4c_category_delete(s_pCategory);
*/
    log4c_fini();
}

